package com.capgemini;

import java.sql.Date;
import java.sql.Time;

import com.capgemini.daos.OlympicAdressDao;
import com.capgemini.daos.PerformanceDao;
import com.capgemini.daos.PersonDao;
import com.capgemini.daos.TournamentDao;
import com.capgemini.data.Athlete;
import com.capgemini.data.Discipline;
import com.capgemini.data.OlympicAdress;
import com.capgemini.data.Performance;
import com.capgemini.data.Person;
import com.capgemini.data.Tournament;
import com.capgemini.data.Trainer;

public class Main {

	/**
	 * @param args
	 * @throws Exception
	 * @throws InstantiationException
	 */
	@SuppressWarnings("deprecation")
	public static void main(String[] args) throws InstantiationException,
			Exception {

		// PersonDao testing
		PersonDao persdao = new PersonDao();
		OlympicAdressDao adressDao = new OlympicAdressDao();
		PerformanceDao perfdao = new PerformanceDao();

		Athlete cold = new Athlete("Usain", "Cold", new Date(80, 0, 27),
				"Jamaica", Discipline.SPRINT100M, 1);
		cold = (Athlete) persdao.save(cold);
		Athlete white = new Athlete("James", "White", new Date(81, 0, 6),
				"Trinidad", Discipline.SPRINT200M, 25);
		white = (Athlete) persdao.save(white);
		OlympicAdress address = new OlympicAdress("Kerkstraat", 89, "London");

		// Save address
		address = adressDao.save(address);
		white.setAdress(address);
		white = (Athlete) persdao.save(white);
		address.setPerson(white);
		address = adressDao.save(address);
		OlympicAdress loadedAddress = adressDao.load(OlympicAdress.class,
				address.getId());

		cold.addDopingHistory("2004: EPO");
		cold.addDopingHistory("2010: Bloodtransfusion");
		cold = (Athlete) persdao.save(cold);
		Athlete blacky = new Athlete("Jamy", "Blaky", new Date(81, 0, 6),
				"Tobago", Discipline.SPRINT200M, 255);
		blacky = (Athlete) persdao.save(blacky);
		persdao.delete(blacky);
		Person temppers = persdao.load(Person.class, 2);
		Trainer delb = new Trainer("Anton", "Del Bosque", new Date(52, 1, 14),
				"Brasil", true, "main coach");
		delb = (Trainer) persdao.save(delb);
		cold.addTrainer(delb);
		cold = (Athlete) persdao.save(cold);

		// TournamentDao testing
		TournamentDao tourdao = TournamentDao.class.newInstance();
		Tournament wk = new Tournament("WK", "Helsinki", 83, new Date(112, 6,
				17), new Date(112, 6, 20), Discipline.SPRINT200M);
		wk = tourdao.save(wk);
		Tournament temptour = tourdao.load(Tournament.class, 1);
		System.out.println(temptour.getLocation());
		wk.setLocation("Diegem");
		wk = tourdao.save(wk);
		Tournament ek = new Tournament("EK", "Paris", 79, new Date(109, 6, 11),
				new Date(109, 6, 18), Discipline.MARATHON);
		ek = tourdao.save(ek);
		Performance perf1 = new Performance(new Time(2345000), 1, true, cold,
				wk);
		wk.addPerformance(perf1);
		wk = tourdao.save(wk);
		perf1 = wk.getPerformances().iterator().next();

		cold.addPerformance(perf1);
		cold = (Athlete) persdao.save(cold);
		Performance perf2 = new Performance(new Time(8346000), 3, false, white,
				wk);
		white.addPerformance(perf2);
		white=(Athlete)persdao.save(white);
		perf2=white.getPerformances().iterator().next();
		wk.addPerformance(perf2);
		wk = tourdao.save(wk);
		cold = (Athlete) persdao.save(cold);
	}
}
